﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using OnlineSchool.Model.Entities;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace OnlineSchool.Data
{
    public class WebDbContext : DbContext
    {
        public WebDbContext()
            : base("name=WebSiteConn")
        {
            //Database.Initialize(true);
        }

        public DbSet<Category> Categories { get; set; }
        public DbSet<Expense> Expenses { get; set; }
        public DbSet<User> Users { get; set; }
        public virtual void Commit()
        {
            base.SaveChanges();
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // 移除EF的表名公约      
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            // 移除对MetaData表的查询验证
            modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
            modelBuilder.Entity<Category>().ToTable("CATEGORIES");
            modelBuilder.Entity<Expense>().ToTable("EXPENSE");
            modelBuilder.Entity<User>().ToTable("USER");
        }
       
    }
}
